using System;
using System.Collections.Specialized;
using System.Xml;

namespace AMS.Core.Helper
{
    public class XmlEnumHelper
    {
        public string m_XmlSettingFilePath;

        public XmlEnumHelper()
        {
            m_XmlSettingFilePath = AppDomain.CurrentDomain.BaseDirectory + "Setting\\EnumProperty.xml";
        }
		
        private string GetEnumNodeAttrVal(XmlNode nd,string attrName)
        {
            string reVal = "";
            if(nd.Attributes[attrName]!=null&&nd.Attributes[attrName].Value!=null)
            {
                reVal = nd.Attributes[attrName].Value;
            }
            return reVal;
        }

        public NameValueCollection GetValue(string enumName)
        {
            NameValueCollection nvc = new NameValueCollection();
            XmlDocument doc = new XmlDocument();
            doc.Load(m_XmlSettingFilePath);
            XmlNode e = doc.SelectSingleNode("Enums/"+enumName);
            if(e==null)
                throw new ArgumentException("?????????????????");
            for(int i=0;i<e.ChildNodes.Count;i++)
            {
                XmlNode n = e.ChildNodes[i];
                string strVal = GetEnumNodeAttrVal(n,"Value");
                string strName = GetEnumNodeAttrVal(n, "Name");
                nvc.Add(strVal,strName);
            }
            return nvc;
        }

        public NameValueCollection WoState
        {
            get { return GetValue("WoState"); }
        }
    }
}
